package com.sctvcloud.bazhong.ui.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.ruihang.generalibrary.ui.adapter.BaseHolderAbsAdapter;
import com.ruihang.generalibrary.ui.util.OnItemInternalClick;
import com.sctvcloud.bazhong.R;
import com.sctvcloud.bazhong.beans.FRebellion;
import com.sctvcloud.bazhong.ui.adapter.holder.ApplyHolder;
import com.sctvcloud.bazhong.ui.adapter.holder.ImgHolder;
import com.sctvcloud.bazhong.ui.adapter.holder.ShareHolder;
import com.sctvcloud.bazhong.ui.adapter.holder.BaseRebllionHolder;
import com.sctvcloud.bazhong.ui.adapter.holder.TopicHolder;
import com.sctvcloud.bazhong.ui.util.IListShowData;

import java.util.List;

/**
 * Created by Administrator on 2017/6/26 0026.
 */

public class ShareAdapter extends BaseHolderAbsAdapter<IListShowData, BaseRebllionHolder> implements OnItemInternalClick {
    private OnItemInternalClick onItemInternalClick;
    private TopicHolder.OnTopicSelectListener listener;

    private OnVideoClickListener mListener;
    private int reward; // 3是举报有奖   4是互动分享

    public int isReward() {
        return reward;
    }

    public void setReward(int reward) {
        this.reward = reward;
    }

    public ShareAdapter(Context context, List<IListShowData> list,TopicHolder.OnTopicSelectListener listener) {
        super(context, list);
        this.listener = listener;
    }

    @Override
    public BaseRebllionHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        BaseRebllionHolder rebllionHolder;
        LayoutInflater inflater = LayoutInflater.from(context);
        if(viewType == 1){
            rebllionHolder = new TopicHolder(context, inflater.inflate(R.layout.item_topic, parent, false),listener);
            rebllionHolder.setInternalClick(this);
        }else if(viewType == 2){
            rebllionHolder = new ImgHolder(context, inflater.inflate(R.layout.item_img, parent, false));
            rebllionHolder.setInternalClick(this);
        }else {
            rebllionHolder = new ShareHolder(context, inflater.inflate(R.layout.item_share_plate, parent, false));
            rebllionHolder.setInternalClick(this);
            ((ShareHolder) rebllionHolder).setReward(reward);
        }
        return rebllionHolder;
    }

    @Override
    public int getItemViewType(int position) {
        return data.get(position).getDataViewType();
    }

    @Override
    public void onItemInternalClick(View itemView, View view, int position) {
        if (onItemInternalClick != null) {
            onItemInternalClick.onItemInternalClick(itemView, view, position);
        }
    }

    @Override
    public ShareAdapter setItemInternalClick(OnItemInternalClick itemInternalClick) {
        this.onItemInternalClick = itemInternalClick;
        return this;
    }

    public void setOnVideoClickListener(OnVideoClickListener listener) {
        mListener = listener;
    }

    public interface OnVideoClickListener {
        void onVideoClick(View view, View coverImgView, FRebellion fRebellion);
    }
}
